package com.oceansoft.mobile.biz.api.controller;

import com.oceansoft.mobile.biz.api.service.IApiUploadPictureService;
import com.oceansoft.mobile.common.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by lenovo on 2017/5/3.
 */
@Controller
@RequestMapping(value = "api/uploadPic")
public class ApiUploadPictureController {
    @Resource
    private IApiUploadPictureService apiUploadPictureService;

    /**
     * 咨询投诉和违法举报犯罪的图片上传
     * @param serviceId
     * @param model
     * @param session
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "uploadimg/{serviceId}/{localid}", method = RequestMethod.GET)
    public Result img(@PathVariable("serviceId") String serviceId,@PathVariable("localid") String localid, Model model, HttpSession session, HttpServletRequest request) {
        String url = "http://172.16.1.250/e/extend/index.php?s=api/upfile";
        try {
            Result result = apiUploadPictureService.saveAppFjTx(request);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(Result.FAILURE, "");
    }

    /**
     * 货车临时同行证
     * 施工车辆通行证
     * 申请门牌号
     * 律师网上预约
     * 行政复议
     * 户口在线办理
     * 图片上传
     * @param serviceId
     * @param type
     * @param name
     * @param model
     * @param session
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "uploadOneimg/{serviceId}/{type}/{name}", method = RequestMethod.GET)
    public Result Oneimg(@PathVariable("serviceId") String serviceId,@PathVariable("type") String type,@PathVariable("name") String name, Model model, HttpSession session, HttpServletRequest request) {
        try {
            Result result = apiUploadPictureService.saveOneFjTX(request, serviceId,type, name);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(Result.FAILURE, "");
    }

    /**
     * 养犬管理
     * 图片上传
     * @param serviceId
     * @param type
     * @param name
     * @param model
     * @param session
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "uploadDogimg/{serviceId}/{type}/{name}", method = RequestMethod.GET)
    public Result Dogimg(@PathVariable("serviceId") String serviceId,@PathVariable("type") String type,@PathVariable("name") String name, Model model, HttpSession session, HttpServletRequest request) {
        try {
            Result result = apiUploadPictureService.saveDogFjTX(request, serviceId,type, name);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(Result.FAILURE, "");
    }

    /**
     * 法制投诉立案图片上传
     * @param serviceId
     * @param model
     * @param session
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "uploadFZimg/{serviceId}", method = RequestMethod.GET)
    public Result uploadFZimg(@PathVariable("serviceId") String serviceId, Model model, HttpSession session, HttpServletRequest request) {
        try {
            Result result = apiUploadPictureService.saveFZFjTX(request,serviceId);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(Result.FAILURE, "");
    }

    /**
     * app上传图片
     *  * 货车临时同行证
     * 施工车辆通行证
     * 申请门牌号
     * 律师网上预约
     * 行政复议
     * 户口在线办理
     * 图片上传
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "appUploadOneImg", method = RequestMethod.POST)
    public Result appUploadOneImg(HttpServletRequest request){
        try{
            Result result=apiUploadPictureService.saveAppOneFjTx(request);
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  new Result(Result.FAILURE,"");
    }

    /**
     * app养犬上传图片
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "appUploadDogImg", method = RequestMethod.POST)
    public Result appUploadDogImg(HttpServletRequest request){
        try{
            Result result=apiUploadPictureService.saveAppDogFjTx(request);
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  new Result(Result.FAILURE,"");
    }

    /**
     * app违法举报犯罪和咨询投诉
     * 上传图片
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "appUploadImg", method = RequestMethod.POST)
    public Result appUploadImg(HttpServletRequest request){
        try{
            Result result=apiUploadPictureService.saveAppFjTx(request);
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  new Result(Result.FAILURE,"");
    }
    @ResponseBody
    @RequestMapping(value = "appUploadFZImg", method = RequestMethod.POST)
    public Result appUploadFZImg(HttpServletRequest request){
        try{
            Result result=apiUploadPictureService.saveAppFZFjTx(request);
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return  new Result(Result.FAILURE,"");
    }
}
